package com.ygp.lock.rlock.threadsinal;

import com.ygp.utils.Sleeper;

import java.util.stream.IntStream;

/**
 * <Description> <br>
 *
 * @author linmiaolai@sanyygp.com<br>
 * @version 1.0<br>
 * @date 2021/11/19 <br>
 */
public class BoundedContainerTest {
    public static void main(String[] args) throws InterruptedException {
        test2();
    }

    private static void test2() {
        BoundedContainer container = new BoundedContainer(5);
        IntStream.range(0, 3).forEach(i -> new Thread(() -> {
            try {
                container.put("hello " + i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start());
        IntStream.range(0, 5).forEach(i -> new Thread(() -> {
            try {
                container.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start());
    }

    private static void test1() throws InterruptedException {
        BoundedContainer container = new BoundedContainer(5);
        container.put(1);
        container.put(2);
        container.put(3);
        container.put(4);
        container.put(5);
        System.out.println(container.take());
        container.put(6);
        container.print();
    }
}
